' ' FDIM 2014 QRPP HAMfest STICK ' ' CW Blinker ' ' Written by Dave Rajnauth, VE3OOI (c) 2014 ' ' Version 0.1 June 2014 'Memory Layout for 14M2 ' Program Memory: 2048 bytes Flash Memory: 100K Writable ' Data Memory: EEPROM Memory: 256 Bytes ' Use EEPROM or DATA commands, accessed via READ and WRITE Commands ' General Purpose Variables - 14 bytes - b0-, accessed via Peek and Poke commands at addresses $32 to $3F. ' PICAXE-14M2/20M2 484 bytes from location 28 to 511 ($1C to $1FF) '‘M’ parts has 48 bytes from location 80 to 127 ($50 to $7F) ' Storage variables for 40M2 483 Bytes ' Scratchpad variables for 40M2 1024 Bytes ' Connections ' Pin Function ' 5 c.2 KBCLK ' 6 c.1 KBDATA ' 7 c.0 Osc On (3.6864 Mhz) ' 11 b.2 LED ' ' declarations #picaxe 14m2 #com 1 ' open terminal after download #terminal 9600 ' Don't forget to move serial cable to the hardware pins! 'Lookup table for CW ' for alpha characters subtract 65 from ascii value to get offset in table ' for numeric characters subtract 26 from ascii value to get offset in table ' 'const unsigned char cwLooup[CW_LOOKUP_TABLE_SIZE] = { ' %xxxxxNNN NNN = number of bits for character & xxxxx is 0 for dot, 1 for dash ' %01000010, ' A Subtract 65 from ascii value ' %10000100, ' b ' %10100100, ' c ' %10000011, ' d ' %00000001, ' e ' %00100100, ' f ' %11000011, ' g ' %00000100, ' h ' %00000010, ' i ' %01110100, ' j ' %10100011, ' k ' %01000100, ' l ' %11000010, ' m ' %10000010, ' n ' %11100011, ' o ' %01100100, ' p ' %11010100, ' q ' %01000011, ' r ' %00000011, ' s ' %10000001, ' t ' %00100011, ' u ' %00010100, ' v ' %01100011, ' w ' %10010100, ' x ' %10110100, ' y ' %11000100, ' z ' %11111101, ' 0 [26] ie 48-26=22 Subtract 22 from ascii value ' %01111101, ' 1 ' %00111101, ' 2 ' %00011101, ' 3 ' %00001101, ' 4 ' %00000101, ' 5 ' %10000101, ' 6 ' %11000101, ' 7 ' %11100101, ' 8 ' %11110101, ' 9 ' }' ' That is: 'A - 66 B - 132 C - 164 D - 131 E - 1 F - 36 'G - 195 H - 4 I - 2 J - 116 K - 163 L - 68 'M - 194 N - 130 O - 227 P - 100 Q - 212 R - 67 'S - 3 T - 129 U - 35 V - 20 W - 99 X - 148 'Y - 180 Z - 196 1 - 125 2 - 61 3 - 29 4 - 13 '5 - 5 6 - 133 7 - 197 8 - 229 9 - 245 0 - 253 TABLE 0,(%01000010, %10000100, %10100100, %10000011, %00000001, %00100100, %11000011, %00000100, _ %00000010, %01110100, %10100011, %01000100, %11000010, %10000010, %11100011, %01100100, %11010100, _ %01000011, %00000011, %10000001, %00100011, %00010100, %01100011, %10010100, %10110100, %11000100, _ %11111101, %01111101, %00111101, %00011101, %00001101, %00000101, %10000101, %11000101, %11100101, _ %11110101) TABLE 37,($1c,$32,$21,$23,$24,$2b,$34,$33,$43,$3b,$42,$4b,$3a,$31,$44,$4d,$15,$2d,$1b,$2c,$3c,$2a, _ $1d,$22,$35,$1a,$45,$16,$1e,$26,$25,$2e,$36,$3d,$3e,$46) EEPROM 0,(14,"CQ DE VE300I K") Symbol LookupTableLength = 36 'set length of the CW/KBD lookup table Symbol KBLookupTableStart = 37 'Starting address of the KBD scan code lookup table Symbol Dit_length = 120 'set length of a dot Symbol Dah_length = 360 'set length of a dash 3x dit Symbol ASCIICharacter = b0 'set register for Ascii character message to be send via Morse. Symbol CWCharacter = b1 'set register for Translated CW Character. Symbol ASCIILength = b2 'set register for length of Ascii character message Symbol CWLength = b3 'set register for length of CW character. Symbol i = b4 'counter Symbol j = b5 'counter Symbol k = b6 'counter Symbol KeyPress = b7 'Keyboard Character received Setup: setfreq m8 ' set Fosc for 8 Mhz main: high c.4 high c.0 for i=0 to 2 low c.4 pause 500 high c.4 pause 500 next i if pinB.2 != 1 then keyled %00000111 do KBIN KeyPress if KeyPress > 0 then sertxd("Key Press: ", #KeyPress) gosub LookupKBDScanCode sertxd(" Ascii: ", #ASCIICharacter) endif loop while KeyPress != $5a endif Start: READ 0,ASCIILength for i=1 to ASCIILength read i, ASCIICharacter ' read value from table gosub SendCW next i high c.4 high c.0 gosub Word_sp Sleep 1 goto Start SendCW: gosub LookupCW let CWLength = CWCharacter & %00000111 'Lower 3 bits is the length of the CW charater if CWLength = 0 then gosub Word_sp return endif ' for j=1 to CWLength 'loop through correct no. of times for number of elements if CWCharacter >= 128 then gosub Dash 'test MS digit of ch. If it is 1 goto the Dah sub routine else gosub Dot 'if it is 0 goto the Dit sub routine endif let CWCharacter = CWCharacter * 2 'do a left shift on all the bits in ch. next gosub Char_sp 'Character send so insert a intercharacter space return LookupKBDScanCode: let k = KBLookupTableStart+LookupTableLength-1 for j=KBLookupTableStart to k readtable j, ASCIICharacter sertxd(" ", #ASCIICharacter) if KeyPress = ASCIICharacter then if j > 22 then let ASCIICharacter = j + 22 'This is a number else let ASCIICharacter = j + 65 'This is a alpha end if else ASCIICharacter = 0 end if next j return LookupCW: ' if (c > 64) c -= 65' ' else if (c > 47) c -= 22' if ASCIICharacter > 64 then let ASCIICharacter = ASCIICharacter - 65 else if ASCIICharacter > 47 then let ASCIICharacter = ASCIICharacter - 22 else let CWCharacter = 0 return end if readtable ASCIICharacter, CWCharacter ' read CW value from table return Dot: low c.0 ' turn on osc for dit_length low c.4 ' turn on LED for dit_length pause Dit_Length ' pause for dit_length high c.0 ' turn on osc for dit_length high c.4 ' turn on LED for dit_length pause Dit_Length ' character spacing return ' return to look at next element of ch. Dash: low c.0 ' turn on osc for dit_length low c.4 ' turn on LED for dit_length pause Dah_Length ' pause for dit_length high c.0 ' turn on osc for dit_length high c.4 ' turn on LED for dit_length pause Dit_Length ' character spacing return ' return to look at next element of ch. Word_sp: pause Dah_Length ' pause for 7x dit length for space between words but alread waited 1 dit length pause Dah_Length ' each dah length = 3x dit length return 'return to get next ch. Char_sp: pause Dit_Length ' pause for 3x dit length but already paused 1 dit length pause Dit_Length ' pause for 7x dit length return 'return to get next ch.